package com.atguigu.flink.chapter5.transform;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink08_Transform_Connect {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> s1 = env.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<String> s2 = env.fromElements("a", "b", "c", "d");
        // 不是真正的合并, 仅仅是放在了一起. 内部还是两个流
        ConnectedStreams<Integer, String> s12 = s1.connect(s2);

        /*s12
          .map(new CoMapFunction<Integer, String, String>() {
              @Override
              public String map1(Integer value) throws Exception {
                  return value * value + "";
              }

              @Override
              public String map2(String value) throws Exception {
                  return value + "<";
              }
          });*/
        s12
          .getFirstInput()
          .print("first");
        s12
          .getSecondInput()
          .print("second");


        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
